package com.company.cloud.ad.modules.app.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.company.cloud.ad.modules.cache.models.AdModel;
import com.company.cloud.ad.modules.cache.service.AdCacheService;
import com.company.cloud.common.bean.BaseResult;
import com.company.cloud.common.constant.BaseReturnEnum;
import com.company.cloud.common.exception.BusinessException;
import com.company.cloud.common.redis.service.RedisUtils;
import com.company.cloud.common.utils.AuthContextUtils;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 广告
 */
@RestController
@RequestMapping("/app/ad")
@Api(tags="App_Ad_广告")
public class AdController {

    @Autowired
    private AdCacheService adCacheService;
    @Autowired
    private RedisUtils redisUtils;

    @GetMapping("/getByPosition")
    @ApiOperation(value="根据广告位获取内容",response= AdModel.class)
    public BaseResult get(@RequestParam("positionNo")String positionNo) {
        if(StringUtils.isEmpty(positionNo)){
           throw new BusinessException(BaseReturnEnum.DATA_NOT_EXISTS);
        }
        //LoginUserInfo userInfo= AuthContextUtils.getUser2Head(redisUtils);
        List<AdModel> data= adCacheService.getAdByCache(positionNo, AuthContextUtils.getCompanyNo());
        return BaseResult.ok(data);
    }
}
